package com.seven.thread;

import java.util.concurrent.Callable;

/**
 * @author sevenDay
 * @classname SevenCallable
 * @description: 抽象包装callable的线程任务
 * @date 2018/7/16
 */

public abstract class SevenCallable<V> implements Callable<V>,ThreadTask {

    private int taskId;
    private String taskName;
    private long startTime;
    private long endTime;

    public SevenCallable(String taskName,int taskId){
        this.taskName = taskName;
        this.taskId = taskId;
    }
    /**
     * 设置线程的任务Id，可以是严格排序的Id
     * @param taskId
     */
    @Override
    public  void setTaskId(int taskId){this.taskId=taskId;};

    /**
     * 设置线程的任务名称
     * @param taskName
     */
    @Override
    public  void setTaskName(String taskName){this.taskName=taskName;};

    /**
     *用于实现线程执行的过程
     * @return
     * @throws Exception
     */
    @Override
    public abstract V call() throws Exception;

    /**
     * 设置线程开始执行时间，用于统计线程执行效率
     * @param startTime
     */
    @Override
    public void setStartTime(long startTime){this.startTime=startTime;};

    /**
     * 设置线程执行结束的时间，便于统计线程的执行效率和任务耗时量
     * @param endTime
     */
    @Override
    public  void setEndTime(long endTime){this.endTime=endTime;};

    @Override
    public String getTaskName() {
        return this.taskName;
    }
    @Override
    public int getTaskId() {
        return this.taskId;
    }
    @Override
    public long getStartTime() {
        return this.startTime;
    }
    @Override
    public long getExecuteTime() {
        return this.endTime-this.startTime;
    }

    @Override
    public long getEndTime() {
        return this.endTime;
    }

}
